<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="entity.Execution"%>
<%@ page import="dao.ExecutionDAO"%>
<%@ page import="java.sql.*,java.util.*"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<base href="<%=basePath%>">
<title></title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
</head>
<body>
	<hr>
	<div class="panel admin-panel">
		<div class="panel-head">
			<strong class="icon-reorder"> 执行列表</strong>
		</div>
		<form>
			<table class="table table-hover text-center">
				<tr>
					<td width="20%">合同编号</td>
					<td width="40%">执行状态</td>
					<td width="20%">执行操作</td>
					<td width="20%">完成操作</td>
				</tr>
				<%
					ExecutionDAO executionDAO = new ExecutionDAO();
					ArrayList<Execution> list = executionDAO.getAllExecution();

					if (list != null && list.size() > 0) {
						for (int i = 0; i < list.size(); i++) {
							Execution ex = list.get(i);
				%>

				<tr>
					<td><%=ex.getCno()%></td>
					<td><%=ex.getContext()%></td>
					<td><a
						href="servlet/ExcutionServlet?action=edit&cno=<%=ex.getCno()%>"
						onclick="javascript:return excu('<%=ex.getContext()%>')">执行</a></td>
					<td><a
						href="servlet/ExcutionServlet?action=finish&cno=<%=ex.getCno()%>"
							onclick="javascript:return finish('<%=ex.getContext()%>')">完成</a></td>

				</tr>



				<%
					}
					}
				%>
			</table>
		</form>
	</div>
	<script>
		function excu(context) {
			var msg = "您确定要执行吗？\n\n请确认！";
			var c = context;
			if (confirm(msg) == true) {
				if (context == '未执行') {
					alert("执行成功！");
					return true;
				} else if (context == '执行中') {
					alert("该合同正在执行中！");
					return false;
				} else if (context == '已完成') {
					alert("该合同已经完成！");
					return false;
				} else {
					alert("执行失败！");
					return false;
				}

			} else {
				return false;
			}
		}
	</script>
	<script>
		function finish(context) {
			var msg = "您确定合同已经完成了吗？\n\n请确认！";
			var c = context;
			if (confirm(msg) == true) {
				if (context == '未执行') {
					alert("该合同未开始执行！");
					return false;
				} else if (context == '执行中') {
					alert("操作成功!");
					return true;
				} else if (context == '已完成') {
					alert("该合同已经完成！");
					return false;
				} else {
					alert("执行失败！");
					return false;
				}

			} else {
				return false;
			}
		}
	</script>
</body>
</html>